package com.cn.wanxi.service;

import com.cn.wanxi.IO.FileModelIO;
import com.cn.wanxi.IOModel.NavIOModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.util.IOUtil;

import java.util.Arrays;
import java.util.List;

public class NavService {
    public List<NavModel> getNavList(){
        FileModelIO.writeData(IOUtil.NAVPATH.getPath(),new NavIOModel().toString());
        String result = FileModelIO.readData(IOUtil.NAVPATH.getPath());
        String[] navData = FileModelIO.inputDataList(result,IOUtil.SPILT.getPath());
        System.out.println("navDate" + Arrays.toString(navData));
        NavModel navModel = new NavModel();
        String href = navData[0].substring(navData[0].indexOf("[")+1,navData[0].length());
        String title = navData[1].substring(navData[1].indexOf("[")+1,navData[1].length());
        String[] hrefs = href.split(",");
        String[] titles = title.split(",");
        for (int i = 0; i < hrefs.length;i++) {
            NavModel nav = new NavModel();
            nav.setHref(hrefs[i]);
            nav.setTitle(titles[i]);
            navModel.list.add(nav);
            System.out.println(hrefs[i] + ":" + titles[i]);
        }
        return navModel.list;
    }

    public static void main(String[] args) {
        new NavService().getNavList();
    }
}
